import 'package:airbnb_clone/components/dialog/msg_dialog.dart';
import 'package:airbnb_clone/internal/cache/app_cache.dart';
import 'package:airbnb_clone/internal/sqlite/dao/message_dao.dart';
import 'package:flutter/material.dart';

import 'package:flutter_animate/flutter_animate.dart';

import '../constant/constant.dart';

class AnimateMeauList extends StatefulWidget {
  const AnimateMeauList({super.key});

  @override
  State<AnimateMeauList> createState() => _AnimateMeauListState();
}

class _AnimateMeauListState extends State<AnimateMeauList> {
  @override
  Widget build(BuildContext context) {
    return ListView(children: selfSettingBar(context));
  }
}

List<Widget> selfSettingBar(BuildContext context) {
  // final textTheme = Theme.of(context).textTheme;
  List<Widget> widgets = [];
  List titles = ["Setting", "Account", "CleanCache", "Github", "Logout"];
  List<IconData> icons = [
    Icons.settings,
    Icons.person,
    Icons.cleaning_services_sharp,
    Icons.link,
    Icons.exit_to_app_rounded
  ];
  for (var i = 0; i < titles.length; i++) {
    // print(titles[i]);
    widgets.add(
      GestureDetector(
        onTap: () async {
          // print("launchUrl");
          // await launchUrl(Uri.parse("https://github.com/OpencvLZG"),
          // mode: LaunchMode.inAppWebView);
          if (titles[i] == "Logout") {
            AppCache.cleanToken();
            MsgDialog.msgDialog(context, "退出成功");
          } else if (titles[i] == "CleanCache") {
            MessageDao().deleteAllData();
            MsgDialog.msgDialog(context, "删除成功");
          }
        },
        child: Container(
          margin: const EdgeInsets.only(top: 10),
          height: 50,
          width: 400,
          decoration: BoxDecoration(
            color: maskShadowColor,
            borderRadius: BorderRadius.circular(10),
            boxShadow: const [
              // BoxShadow(
              //   color: Colors.blue.withOpacity(0.4),
              //   blurRadius: 8.0,
              //   spreadRadius: 8.0,
              //   offset: const Offset(1, 1),
              // )
            ],
          ),
          child: Padding(
            padding: const EdgeInsets.all(2.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                IconButton(
                  onPressed: () {},
                  icon: Icon(
                    icons[i],
                    color: Colors.black,
                  ),
                ),
                Text(
                  titles[i],
                  style: const TextStyle(
                      color: Colors.black,
                      fontWeight: FontWeight.bold,
                      fontSize: 20),
                ),
                IconButton(
                    onPressed: () {},
                    icon: const Icon(
                      Icons.keyboard_arrow_left_sharp,
                      color: Colors.black,
                      size: 25,
                    ))
              ],
            ),
          ),
        ),
      ),
    );
  }

  widgets = widgets
      .animate(interval: 100.ms)
      .fadeIn(duration: 600.ms, delay: 200.ms)
      .shimmer(
          blendMode: BlendMode.srcOver, color: Colors.black.withOpacity(0.5))
      .move(begin: const Offset(0, 30), curve: Curves.easeOutQuad);
  return widgets;
}
